<?php

namespace Home\Model;
use Think\Model;
class AdvModel extends Model{
    public function AddAdv($post,$file){
        // var_dump($file);exit;
        if(!$file['error']){
            $arr = array(
                'rootPath'  => WORKING_PATH.UPLOAD_ROOT_PATH
                );
            $upload = new \Think\Upload($arr);
            $info = $upload -> uploadOne($file);
            if($info){
                $post['filepath']= UPLOAD_ROOT_PATH . $info['savepath'].$info['savename'];
                $post['filename']=$info['name'];
            }
        }
        $post['time'] = time();
        // var_dump($post);exit;
        return $this -> add($post);
    }
    public function EditAdv($post,$file){
        if(!$file['error']){
            $arr = array(
                'rootPath'  => WORKING_PATH.UPLOAD_ROOT_PATH
                );
            $upload = new \Think\Upload($arr);
            $info = $upload -> uploadOne($file);
            if($info){
                $post['filepath']= UPLOAD_ROOT_PATH . $info['savepath'].$info['savename'];
                $post['filename']=$info['name'];
            }
        }
        return $this -> save($post);
    }
}